import { fileURLToPath, URL } from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
import ElementPlus from 'unplugin-element-plus/vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 按需引入elementPlus组件
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      // 配置elementPlus组件使用sass样式配色系统
      resolvers: [ElementPlusResolver({ importStyle: "sass" })],
    }),
    ElementPlus({
      useSource: true,
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler',
        // 自动导入定制化样式文件进行样式覆盖
        // 配置自动导入全局scss变量
        additionalData: `
          @use "@/styles/element/index.scss" as *;
           @use "@/styles/var.scss" as *;
        `,
        warnDuplicateGlobals: true, // 抑制全局变量重复警告
        quietDeps: true, // 抑制依赖项警告
        sourceMap: false, // 关闭源映射
        outputStyle: 'compressed', // 输出样式
        quiet: true, // 抑制所有警告

      }
    }
  }
})
